//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Digitalsimulator.h"
#include "./Gatter/AND.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	select = false;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
void __fastcall TForm1::Beenden1Click(TObject *Sender)
{
	exit(0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel1ScrollbarDragDrop(TObject *Sender, TObject *Source, int X, int Y)

{
	if( Source->ClassNameIs("TTreeView")){
		TTreeView *s = dynamic_cast<TTreeView *>(Source);
		String string = s->Selected->Text;
		if(string == "AND")
			AND *and = new AND(Panel1,X,Y);
	}else if( Source->ClassNameIs("AND") ){
			AND *and = dynamic_cast<AND *>(Source);
			and->Top = Y;
			and->Left = X;
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel1ScrollbarDragOver(TObject *Sender, TObject *Source, int X, int Y,
		  TDragState State, bool &Accept)
{
	if( Source->ClassNameIs("TTreeView")){
		TTreeView *s = dynamic_cast<TTreeView *>(Source);
		if (!( s->Selected->Text == "Basiskomponenten" || s->Selected->Text == "Gatter")  )
			Accept = true;
		else
			Accept = false;
	}else{
		Accept = true;

    }
}

void __fastcall TForm1::Panel1ScrollbarMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
	if(select){
		Panel1->Refresh();
		HDC hdc = GetDC(Panel1->Handle);
		Canvas->Handle = hdc;
		Canvas->Brush->Style = bsClear;
		Canvas->Rectangle(select_x, select_y, X,Y);

	}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Panel1ScrollbarMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
		  int X, int Y)
{
	if(Button == mbLeft) {
		select = true;
		select_x = X;
		select_y = Y;
	}else if(Button == mbRight){

	}

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Panel1ScrollbarMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
		  int X, int Y)
{
	select = false;
	// select(x,y,X,Y) startx,starty,endx,endy)
	Panel1->Refresh();
}
//---------------------------------------------------------------------------








